package com.jbp.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;


import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jbp.model.User;
import com.jbp.service.UserService;
import io.swagger.annotations.*;
import jdk.nashorn.internal.parser.JSONParser;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.jbp.model.UserPhoto;
import com.jbp.service.UserPhotoService;
import com.jbp.utils.PageUtils;
import com.jbp.utils.R;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 
 *
 * @author lucheng feng
 * @email jbp@gmail.com
 * @date 2020-06-14 21:24:57
 */
@Api(tags ="个人相册--个人相册相关接口" )
@ApiIgnore
@RestController
@RequestMapping("/rest/userphoto")
public class UserPhotoController {


    @Autowired
    private UserPhotoService userPhotoService;


    /**
     * 列表
     */
    @ApiOperation(value="查看个人相册列表",notes="查看个人相册列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功",response = UserPhoto.class),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "token",value = "token",paramType = "query"),
            @ApiImplicitParam(name="sessionId",value = "sessionId",paramType = "query"),
    })
    @GetMapping("/list")
    public R list(@RequestAttribute("userId") Integer userId){
        List<UserPhoto> userPhotos = userPhotoService.queryList(userId);
        return R.ok().put("data", userPhotos);
    }



    /**
     * 保存
     */
    @ApiOperation(value="保存相册",notes="保存相册")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "img",value = "图片名",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",paramType = "query"),
            @ApiImplicitParam(name="sessionId",value = "sessionId",paramType = "query"),
    })
    @PostMapping("/save")
    public R save(@RequestBody UserPhoto userPhoto,@RequestAttribute("userId") Integer userId){
            userPhoto.setUserId(userId);
            userPhoto.setCreateTime(new Date());
            userPhotoService.save(userPhoto);
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation(value="修改相册",notes="修改相册")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "编号",paramType = "query"),
            @ApiImplicitParam(name = "img",value = "图片路径",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",paramType = "query"),
            @ApiImplicitParam(name="sessionId",value = "sessionId",paramType = "query"),
    })
    @PostMapping("/update")
    public R update(@RequestBody UserPhoto userPhoto){
        userPhotoService.updateById(userPhoto);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @ApiOperation(value="删除相册列表",notes="删除相册列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "成功"),
            @ApiResponse(code = 201,message = "返回失败信息")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "相册编号集合[1,2,3]",paramType = "query"),
            @ApiImplicitParam(name = "token",value = "token",paramType = "query"),
            @ApiImplicitParam(name="sessionId",value = "sessionId",paramType = "query"),
    })
    @PostMapping("/delete")
    public R delete(@RequestBody Integer [] ids){
        userPhotoService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
